<?php
/**
 * Created by PhpStorm.
 * User: sunvou
 * Date: 2018/6/8
 * Time: 下午4:08
 */

namespace App\Http\Controllers;


use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class DeploymentController extends BaseController
{
    public function deploy(Request $request)
    {

        error_reporting(1);
      
      	$target = '/www/wwwroot/LaraBBS'; // 生产环境web目录
      
      	$secret = 'ukXYgIuSn5gX63txdi3E8L6Xq4ks7nolJpihP6yL';
      	
       	$json = json_decode(file_get_contents('php://input'), true);
 
		if (empty($json['password']) || $json['password'] !== $secret) {
	    	exit('error request');
		}
      
       	$cmd = "cd $target && sudo -Hu www  git pull";
	
		shell_exec($cmd);
       

    }
  
    
}